import { Component, OnInit, ViewChild } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { GridComponent, SupDic, HttpService } from 'lbf';
import { SFComponent, SFSchema } from '@delon/form';
import { STColumn } from '@delon/abc';
import { Router, NavigationExtras } from '@angular/router';
import { NzMessageService } from 'ng-zorro-antd';

@Component({
  selector: 'app-zwybpub-tyfs',
  templateUrl: './tyfs.component.html',
})
export class ZwybpubTyfsComponent implements OnInit {
  constructor(
    private supdic: SupDic,
    private router: Router,
    private lbservice: HttpService,
    public msgSrv: NzMessageService,
  ) { }
  date: any = {}; //业务员列表
  LS_DAD010: any; //事项编码
  isPzVisible = false;
  getparams: NavigationExtras;
  queryFormData: any;

  searchSchema: SFSchema = {
    properties: {
      DAD017: {
        type: 'string',
        title: '主事项名称',
        enum: this.supdic.getSFDic('DAD017'),
        ui: {
          widget: 'select',
          allowClear: true,
        },
      },
      DAD075: {
        type: 'string',
        title: '申请人姓名',
      },
      PROJID: {
        type: 'string',
        title: '办件编码',
      },
      SDATE: {
        type: 'string',
        title: '开始时间起',
        ui: { widget: 'date' },
      },
      EDATE: {
        type: 'string',
        title: '开始时间止',
        ui: { widget: 'date' },
      }
    },
    ui: {
      spanLabelFixed: 100,
      grid: {
        span: 8,
      },
    },
  };


  //添加业务人员查询条件
  rysearchSchema: SFSchema = {
    properties: {
      AAE011: {
        type: 'string',
        title: '转移账号',
      },
      AAC003: {
        type: 'string',
        title: '转移人员姓名',
      },
    },
    ui: {
      spanLabelFixed: 120,
      grid: {
        span: 8,
      },
    },
  };

  columns: STColumn[] = [
    {
      title: '主事项名称',
      index: 'DAD017',
      dic: 'DAD017',
      fixed: 'left',
      width: '100px'
    },
    { title: '环节', index: 'DAD024', dic: 'DAD024', },
    { title: '子事项名称', index: 'DAD031', },
    { title: '来源', index: 'DAD072', dic: 'DAD072', },
    { title: '统筹区', index: 'AAA027', dic: 'AAA027', },
    { title: '办件编码', index: 'PROJID', },
    { title: '申请方类型', index: 'DAD036', dic: 'DAD036', },
    { title: '申请者名称', index: 'DAD075', },
    { title: '申请证件号码', index: 'DAD070', dic: 'DAD070', },
    { title: '申请证件类型', index: 'DAD074', dic: 'DAD074', },
    { title: '联系人姓名', index: 'DAD113', },
    { title: '联系证件号码', index: 'DAD114', },
    { title: '联系证件类型', index: 'DAD116', dic: 'DAD074', },
    { title: '联系手机号码', index: 'DAD115', },
    { title: '开始时间', index: 'DAD096', type: 'date', },
    {
      title: '操作区',
      width: '50px',
      fixed: 'right',
      buttons: [
        {
          text: '复核',
          click: (record: any) => this.tysl(record),
        },
        {
          text: '转移',
          click: (record: any) => this.sxzy(record),
        },
      ],
    },
  ];
  //业务人员信息
  ryColumns: STColumn[] = [
    { title: '用户ID', index: 'AAE011' },
    { title: '转移账号', index: 'UNAME' },
    { title: '转移人员姓名', index: 'AAC003' },
    {
      title: '操作区',
      buttons: [
        {
          text: '添加',
          click: record => this.rwzy(record),
        },
      ],
    },
  ];

  params = {
    sname: 'query_tyfs',
    form: {},
  };

  @ViewChild('st', { static: true }) st: GridComponent;
  @ViewChild('st1', { static: true }) st1: GridComponent;
  @ViewChild('sf', { static: false }) sf: SFComponent;
  @ViewChild('sf1', { static: false }) sf1: SFComponent;

  ngOnInit() { }

  _onReuseInit(): void {
    this.query();
  }

  query() {
    this.st.reload(this.sf.value);
  }

  reset() {
    this.sf.formData = null;
    this.sf.reset();
  }

  tysl(record) {
    /**
     * 这里加入是否已办理的判断
     */
    this.lbservice
      .lbservice('query_ywlz', {
        para: { DAD069: record.DAD069, DAD090: '5' },
      })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
          this.query();
        } else {
          this.getparams = {
            queryParams: {
              PROJID: record.PROJID,
              DAD069: record.DAD069,
              DAD017: record.DAD017,
            },
          };
          //跳转
          this.router.navigate([record.TZDZ], this.getparams);
        }
      });
  }
  handlePzCancel() {
    this.isPzVisible = false;
  }
  //操作员查询页面显示
  sxzy(record) {
    this.LS_DAD010 = record.DAD010;
    this.isPzVisible = true;
  }
  //任务转移过程
  rwzy(record) {
    this.lbservice
      .lbservice('rwzy_ADD', {
        para: { DAD010: this.LS_DAD010, AAE011: record.AAE011 },
      })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.msgSrv.info('该任务转移成功');
          this.isPzVisible = false;
        }
      });
  }
  // 业务人员查询
  yw_query() {
    this.lbservice
      .lbservice('YW_QUERY', {
        para: { sf1: this.sf1.value, DAD010: this.LS_DAD010 },
      })
      .then(resdata => {
        this.date = resdata.message.list;
      });
  }
  // tslint:disable-next-line: member-ordering
  modalPzTitle = '操作员信息';
}
